package com.cn.wanxi.servlet.company;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/producat/companyfindById")
public class CompanyFindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String id=req.getParameter("id");
        int companyid = id == null ? 0: Integer.parseInt(id);

        ICompanyService iCompanyService=new CompanyServiceImpl();

        CompanyModel companyModel=iCompanyService.findById(companyid);

        req.getSession().setAttribute("logo",companyModel.getLogo());

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("companyModel",companyModel);
        resp.getWriter().println(jsonObject);
    }
}
